<template>
	<view>
		<view style="margin-left:20px;margin-right: 20px;padding-top:30px">			
			<view class="uni-btn-v" style="text-align: center;margin-bottom:30px;">
				<u-icon name="scan" :size="180" @click="scan" color="#4790EF"></u-icon>
				<!-- <u-button type="primary" @click="scan">扫一扫</u-button> -->
			</view>
			<view class="uni-title">扫码结果：</view>
				<view class="uni-list" v-if="result">
					<view class="uni-cell">
						<view class="scan-result">
							{{result}}
						</view>
					</view>
					<u-form :model="model" ref="uForm"  >
						<u-form-item  label-width="130" :label-position="labelPosition" label="资产类别:"  >
							<u-input  :disabled="disabled"   :border="border" placeholder="" v-model="model.classfullname" type="text"></u-input>
						</u-form-item>
						<u-form-item  label-width="130" :label-position="labelPosition" label="资产编号:"  >
						 	<u-input  :disabled="disabled"   :border="border" placeholder="" v-model="model.uuid" type="text"></u-input>
						 </u-form-item>
				 
						 <u-form-item  label-width="130" :label-position="labelPosition" label="序列:"  >
						  	<u-input  :disabled="disabled"   :border="border" placeholder="" v-model="model.sn" type="text"></u-input>
						  </u-form-item>
						  
						 <u-form-item  label-width="130" :label-position="labelPosition" label="规格型号:"  >
						 	<u-input  :disabled="disabled"  :border="border" placeholder="" v-model="model.model" type="text"></u-input>
						 </u-form-item>
						 
						 <u-form-item  label-width="130" :label-position="labelPosition" label="资产状态:">
						 	<u-input  :disabled="disabled"  :border="border" placeholder="" v-model="model.recyclestr" type="text"></u-input>
						 </u-form-item>
						 
						 <u-form-item  label-width="130" :label-position="labelPosition" label="来源:" >
						 	<u-input  :disabled="disabled"  :border="border" placeholder="" v-model="model.zcsourcestr" type="text"></u-input>
						 </u-form-item>
						 <u-form-item  label-width="130" :label-position="labelPosition" label="供应商:"  >
						 	<u-input  :disabled="disabled"  :border="border" placeholder="" v-model="model.wbsupplierstr" type="text"></u-input>
						 </u-form-item>
						 <u-form-item  label-width="130" :label-position="labelPosition" label="品牌:"  >
						 	<u-input  :disabled="disabled"  :border="border" placeholder="" v-model="model.brandstr" type="text"></u-input>
						 </u-form-item>
						 <u-form-item  label-width="130" :label-position="labelPosition" label="使用年限:"  >
						 	<u-input :disabled="disabled"  :border="border" placeholder="" v-model="model.usefullifestr" type="text"></u-input>
						 </u-form-item>
						 
						 <u-form-item  label-width="130" :label-position="labelPosition" label="其他标签:"  >
						 	<u-input :disabled="disabled"  :border="border" placeholder="" v-model="model.fs20" type="text"></u-input>
						 </u-form-item>
						 
						 <u-form-item  label-width="130" :label-position="labelPosition" label="使用公司"  >
						 	<u-input :disabled="disabled"  :border="border" placeholder="" v-model="model.comp_fullname" type="text"></u-input>
						 </u-form-item>
						 <u-form-item  label-width="130" :label-position="labelPosition" label="使用部门:"  >
						 	<u-input :disabled="disabled"  :border="border" placeholder="" v-model="model.part_fullname" type="text"></u-input>
						 </u-form-item>
						 <u-form-item  label-width="130" :label-position="labelPosition" label="使用人:"  >
						 	<u-input :disabled="disabled"  :border="border" placeholder="" v-model="model.used_username" type="text"></u-input>
						 </u-form-item>
						 
						 <u-form-item  label-width="130" :label-position="labelPosition" label="区域:"  >
						 	<u-input :disabled="disabled"  :border="border" placeholder="" v-model="model.locstr" type="text"></u-input>
						 </u-form-item>
						 
						 <u-form-item  label-width="130" :label-position="labelPosition" label="位置:"  >
						 	<u-input :disabled="disabled"  :border="border" placeholder="" v-model="model.locdtl" type="text"></u-input>
						 </u-form-item>
						 
						 <u-form-item  label-width="130" :label-position="labelPosition" label="备注:"  >
						 	<u-input :disabled="disabled"  :border="border" placeholder="" v-model="model.mark" type="text"></u-input>
						 </u-form-item>
						 
						 <u-form-item  label-width="130" :label-position="labelPosition" label="标签1:"  >
						 	<u-input :disabled="disabled"  :border="border" placeholder="" v-model="model.label1" type="text"></u-input>
						 </u-form-item>
						 
						 <u-form-item  label-width="130" :label-position="labelPosition" label="标签2:"  >
						 	<u-input :disabled="disabled"  :border="border" placeholder="" v-model="model.label2" type="text"></u-input>
						 </u-form-item>
					 
						 
						 <u-form-item  label-width="130" :label-position="labelPosition" label="维保商:"  >
						 	<u-input :disabled="disabled"  :border="border" placeholder="" v-model="model.wbsupplierstr" type="text"></u-input>
						 </u-form-item>
						 <u-form-item  label-width="130" :label-position="labelPosition" label="维保状态:"  >
						 	<u-input :disabled="disabled"  :border="border" placeholder="" v-model="model.wbstr" type="text"></u-input>
						 </u-form-item>
						 <u-form-item  label-width="130" :label-position="labelPosition" label="脱保日期:"  >
						 	<u-input :disabled="disabled"  :border="border" placeholder="" v-model="model.wbout_datestr" type="text"></u-input>
						 </u-form-item>
						 <u-form-item  label-width="130" :label-position="labelPosition" label="维保说明:"  >
						 	<u-input :disabled="disabled"  :border="border" placeholder="" v-model="model.wbct" type="text"></u-input>
						 </u-form-item>
					</u-form>
					
					
				</view>
        	</view>
			
			
			
		</view>
	</view>
</template>
<script>
	import permision from "@/common/permission.js";
	export default {
		data() {
			return {
				title: 'scanCode',
				result: '',
				devinfo:'',
				model: {
					classfullname: '',
					recyclestr:"",
					uuid:"",
					model:"",
					supplierstr:"",
					brandstr:"",
					comp_fullname:"",
					part_fullname:"",					
					used_username:"",
					zcsourcestr:"",			
					wbsupplierstr:"",
					wbstr:"",	
					locstr:"",
					locdtl:"",
					buy_timestr:"",
					ip:"",
					envstr:"",
					sn:"",
					mark:"",
					wbout_datestr:"",
					wbstr:"",
					wbsupplierstr:"",
					wbct:"",
					usefullifestr:"",
					fs20:"",
					label1:"",
					label2:""
				},
				disabled:true,
				border: false,
				check: false,
				labelPosition: 'left'
			}
		},
	 
		methods: {
			async scan() {
				// #ifdef APP-PLUS
				let status = await this.checkPermission();
				if (status !== 1) {
				    return;
				}
				// #endif
				uni.scanCode({
					success: (res) => {
						this.result = res.result;
						this.$u.get('/api/base/res/queryResAll.do', {
							uuid:this.result
						}).then(res => {
							if(res.data.length==1){
								this.model=res.data[0];
							}
						})
					},
					fail: (err) => {
						// #ifdef MP
						uni.getSetting({
							success: (res) => {
								let authStatus = res.authSetting['scope.camera'];
								if (!authStatus) {
									uni.showModal({
										title: '授权失败',
										content: '需要使用您的相机，请在设置界面打开相关权限',
										success: (res) => {
											if (res.confirm) {
												uni.openSetting()
											}
										}
									})
								}
							}
						})
						// #endif
					}
				});
			},
			// #ifdef APP-PLUS
			async checkPermission(code) {
				let status = permision.isIOS ? await permision.requestIOS('camera') :
					await permision.requestAndroid('android.permission.CAMERA');
				if (status === null || status === 1) {
					status = 1;
				} else {
					uni.showModal({
						content: "需要相机权限",
						confirmText: "设置",
						success: function(res) {
							if (res.confirm) {
								permision.gotoAppSetting();
							}
						}
					})
				}
				return status;
			}
			// #endif
		}
	}
</script>

<style scoped lang="scss">
.wrap {
	padding: 30rpx;
	background-color: white;
}
 

.agreement {
	display: flex;
	align-items: center;
	margin: 40rpx 0;

	.agreement-text {
		padding-left: 8rpx;
		color: $u-tips-color;
	}
}
</style>
<style>
	.scan-result {
		min-height: 50upx;
		line-height: 50upx;
	}
</style>
